package com.etone.smartAudit.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.etone.smartAudit.domain.Task;
import com.etone.smartAudit.enums.CheckState;
import com.etone.smartAudit.enums.TaskType;
import com.etone.smartAudit.vo.task.MyDataModelAuthTask;
import com.etone.smartAudit.vo.task.TaskAnalysisTotal;
import com.etone.smartAudit.vo.task.TaskListVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * @author: 蒋学伟
 * @create: 2020-06-23 17:24:39
 * @Description TaskRepository
 */
@Mapper
public interface TaskMapper extends BaseMapper<Task> {

    Task findById(@Param("id") Integer id);

    List<Task> findByParams(@Param("itemTypeId") Integer itemTypeId, @Param("taskType") TaskType taskType);

    /**
     * 同对应的id和项目类型查找一个任务
     *
     * @param itemTypeId
     * @param taskType
     * @return
     */
    Task findOneByItemTypeIdAndType(@Param("itemTypeId") Integer itemTypeId, @Param("taskType") TaskType taskType);

    /**
     * 获取任务列表
     *
     * @param name
     * @param types
     * @param createAdminName
     * @param execAdminName
     * @param createStartTime
     * @param createEndTime
     * @param state
     * @param isOver
     * @param itemId
     * @param createAdminId
     * @param adminId
     * @param isDelay
     * @param parentId
     * @return
     */
    List<TaskListVO> findList(@Param("name") String name, @Param("types") List<TaskType> types, @Param("createAdminName") String createAdminName, @Param("execAdminName") String execAdminName, @Param("createStartTime") Date createStartTime, @Param("createEndTime") Date createEndTime, @Param("state") CheckState state, @Param("isOver") Boolean isOver, @Param("itemId") Integer itemId, @Param("createAdminId") Integer createAdminId, @Param("adminId") Integer adminId, @Param("isDelay") Boolean isDelay, @Param("parentId") Integer parentId);

    /**
     * 获取子任务
     *
     * @param parentId
     * @return
     */
    List<TaskListVO> findChildrenVO(@Param("parentId") Integer parentId);

    /**
     * 查找子任务
     *
     * @param parentId
     * @return
     */
    List<Task> findChildren(@Param("parentId") Integer parentId);

    /**
     * 查找是否有子任务
     *
     * @param parentId
     * @return
     */
    boolean hasChildren(@Param("parentId") Integer parentId);

    /**
     * 数据中台-数据任务申请成功次数
     *
     * @return
     */
    int findWorkDataApplyCnt();

    /**
     * 统计任务总量和平均分
     *
     * @param name
     * @param types
     * @param createAdminName
     * @param execAdminName
     * @param createStartTime
     * @param createEndTime
     * @param state
     * @param isOver
     * @param itemId
     * @param createAdminId
     * @param adminId
     * @return
     */
    TaskAnalysisTotal countTaskCntAndAvg(@Param("name") String name, @Param("types") List<TaskType> types, @Param("createAdminName") String createAdminName, @Param("execAdminName") String execAdminName, @Param("createStartTime") Date createStartTime, @Param("createEndTime") Date createEndTime, @Param("state") CheckState state, @Param("isOver") Boolean isOver, @Param("itemId") Integer itemId, @Param("createAdminId") Integer createAdminId, @Param("adminId") Integer adminId);

    /**
     * 获取任务预计工时和实际工时总量
     *
     * @param name
     * @param types
     * @param createAdminName
     * @param execAdminName
     * @param createStartTime
     * @param createEndTime
     * @param state
     * @param isOver
     * @param itemId
     * @param createAdminId
     * @param adminId
     * @return
     */
    TaskAnalysisTotal sumTaskWorkDay(@Param("name") String name, @Param("types") List<TaskType> types, @Param("createAdminName") String createAdminName, @Param("execAdminName") String execAdminName, @Param("createStartTime") Date createStartTime, @Param("createEndTime") Date createEndTime, @Param("state") CheckState state, @Param("isOver") Boolean isOver, @Param(
            "itemId") Integer itemId, @Param("createAdminId") Integer createAdminId, @Param("adminId") Integer adminId);

    /**
     * 代办任务个数
     *
     * @param createAdminId
     * @return
     */
    Integer countAgency(@Param("createAdminId") Integer createAdminId);

    /**
     * 已办任务个数
     *
     * @param createAdminId
     * @return
     */
    Integer countDone(@Param("createAdminId") Integer createAdminId);

    /**
     * 我的发起任务个数
     *
     * @param createAdminId
     * @return
     */
    Integer countCreate(@Param("createAdminId") Integer createAdminId);

    /**
     * 逾期任务个数
     *
     * @param createAdminId
     * @return
     */
    Integer countBeOverdue(@Param("createAdminId") Integer createAdminId);

    /**
     * 我申请的数据模型任务
     *
     * @param name
     * @param state
     * @param adminId
     * @return
     */
    List<MyDataModelAuthTask> myDataModelAuthList(@Param("name") String name, @Param("state") CheckState state, @Param("adminId") Integer adminId);

    /**
     * 获取有权限的任务
     *
     * @param adminId
     * @param id
     * @return
     */
    Task findPermissionTask(@Param("adminId") Integer adminId, @Param("id") Integer id);
}
